.TH std::this_thread::get_id 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::this_thread::get_id \- std::this_thread::get_id

.SH Synopsis
   Defined in header <thread>
   std::thread::id get_id() noexcept;  \fI(since C++11)\fP

   Returns the id of the current thread.

.SH Parameters

   \fI(none)\fP

.SH Return value

   id of the current thread.

.SH Example


// Run this code

 #include <chrono>
 #include <iostream>
 #include <syncstream>
 #include <thread>
 using namespace std::chrono_literals;

 void foo()
 {
     std::thread::id this_id = std::this_thread::get_id();

     std::osyncstream(std::cout) << "thread " << this_id << " sleeping...\\n";

     std::this_thread::sleep_for(500ms);
 }

 int main()
 {
     std::jthread t1{foo};
     std::jthread t2{foo};
 }

.SH Possible output:

 thread 140113018054400 sleeping...
 thread 140113009661696 sleeping...

.SH See also

   get_id returns the id of the thread
          \fI(public member function of std::thread)\fP
   C documentation for
   thrd_current
